AmCharts.AmExport=AmCharts.Class({construct:function(e,t,i){var r=this;r.DEBUG=false;r.chart=e;r.canvas=null;r.svgs=[];r.userCFG=t;r.buttonIcon="export.png";r.exportPNG=true;r.exportPDF=false;r.exportJPG=false;r.exportSVG=false;r.right=0;r.top=0;r.buttonRollOverColor="#EFEFEF";r.textRollOverColor="#CC0000";r.buttonTitle="Save chart as an image";r.buttonAlpha=.75;r.imageFileName="amChart";r.imageBackgroundColor="#FFFFFF";if(i){r.init()}},toCoordinate:function(e){if(e===undefined){return"auto"}if(String(e).indexOf("%")!=-1){return e}else{return e+"px"}},init:function(){var e=this;var t=[];if(e.exportPNG){t.push("png")}if(e.exportPDF){t.push("pdf")}if(e.exportJPG){t.push("jpg")}if(e.exportSVG){t.push("svg")}var i=[];if(t.length==1){var r=t[0];i.push({format:r,iconTitle:e.buttonTitle,icon:e.chart.pathToImages+e.buttonIcon})}else if(t.length>1){var o=[];for(var n=0;n<t.length;n++){o.push({format:t[n],title:t[n].toUpperCase()})}i.push({onclick:function(){},icon:e.chart.pathToImages+e.buttonIcon,items:o})}var a=e.color;if(a===undefined){a=e.chart.color}var s=e.buttonColor;if(s===undefined){s="transparent"}e.cfg={menuTop:e.toCoordinate(e.top),menuLeft:e.toCoordinate(e.left),menuRight:e.toCoordinate(e.right),menuBottom:e.toCoordinate(e.bottom),menuItems:i,menuItemStyle:{backgroundColor:s,opacity:e.buttonAlpha,rollOverBackgroundColor:e.buttonRollOverColor,color:a,rollOverColor:e.textRollOverColor,paddingTop:"6px",paddingRight:"6px",paddingBottom:"6px",paddingLeft:"6px",marginTop:"0px",marginRight:"0px",marginBottom:"0px",marginLeft:"0px",textAlign:"left",textDecoration:"none",fontFamily:e.chart.fontFamily,fontSize:e.chart.fontSize+"px"},menuItemOutput:{backgroundColor:e.imageBackgroundColor,fileName:e.imageFileName,format:"png",output:"dataurlnewwindow",render:"browser",dpi:90,onclick:function(e,t,i){i.preventDefault();e.output(t)}},removeImagery:true};e.processing={buffer:[],drawn:0,timer:0};if(typeof window.canvg!="undefined"&&typeof window.RGBColor!="undefined"){e.cfg.menuItemOutput.render="canvg"}if(typeof window.saveAs!="undefined"){e.cfg.menuItemOutput.output="save"}if(AmCharts.isIE&&AmCharts.IEversion<10){e.cfg.menuItemOutput.output="dataurlnewwindow"}var l=e.userCFG;if(l){l.menuItemOutput=AmCharts.extend(e.cfg.menuItemOutput,l.menuItemOutput||{});l.menuItemStyle=AmCharts.extend(e.cfg.menuItemStyle,l.menuItemStyle||{});e.cfg=AmCharts.extend(e.cfg,l)}e.chart.AmExport=e;e.chart.addListener("rendered",function(){e.setup()});if(e.DEBUG){window.AmExport=e}},log:function(){console.log("AmExport: ",arguments)},setup:function(){var e=this;if(!AmCharts.isIE||AmCharts.isIE&&AmCharts.IEversion>9){e.generateButtons()}},generateBinaryArray:function(e){var t=e.length,i=new Uint8Array(t/4*3|0),r=0,o=0,n=[0,0],a=0,s=0,l,u,g,d=new Uint8Array([62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51]);while(t--){u=e.charCodeAt(r++);l=d[u-43];if(l!==255&&l!==g){n[1]=n[0];n[0]=u;s=s<<6|l;a++;if(a===4){i[o++]=s>>>16;if(n[1]!==61){i[o++]=s>>>8}if(n[0]!==61){i[o++]=s}a=0}}}return i},generateBlob:function(e,t){var i=this,r=t!="image/svg+xml"?e.indexOf(",")+1:0,o=e.substring(0,r),n=e,a=new Blob;if(o.indexOf("base64")!=-1){n=i.generateBinaryArray(e.substring(r))}if(AmCharts.isIE&&AmCharts.IEversion<10){a.data=n;a.size=n.length;a.type=t;a.encoding="base64"}else{a=new Blob([n],{type:t})}return a},generatePDF:function(e){var t=this,i={output:function(){return""}},r=t.canvas.toDataURL("image/jpeg"),o=t.canvas.width*25.4/e.dpi,n=t.canvas.height*25.4/e.dpi;if(window.jsPDF){i=new jsPDF;if(i.addImage){i.addImage(r,"JPEG",0,0,o,n)}else{alert("Missing jsPDF plugin; Please add the 'addImage' plugin.")}}else{alert("Missing jsPDF lib; Don't forget to add the addImage plugin.")}return i},output:function(e,t){var i=this;e=AmCharts.extend(AmCharts.extend({},i.cfg.menuItemOutput),e||{});if(i.chart.prepareForExport){i.chart.prepareForExport()}function r(){var r=null;var o;if(e.format=="image/svg+xml"||e.format=="svg"){r=i.generateSVG();o=i.generateBlob(r,"image/svg+xml");if(e.output=="save"){saveAs(o,e.fileName+".svg")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){o="data:image/svg+xml;base64,"+btoa(r)}else if(e.output=="dataurlnewwindow"){window.open("data:image/svg+xml;base64,"+btoa(r))}else if(e.output=="datauri"||e.output=="dataurl"){location.href="data:image/svg+xml;base64,"+btoa(r)}else if(e.output=="datastream"){location.href="data:image/octet-stream;base64,"+r}if(t){t.apply(i,[o])}}else if(e.format=="application/pdf"||e.format=="pdf"){r=i.generatePDF(e).output("dataurlstring");o=i.generateBlob(r,"application/pdf");if(e.output=="save"){saveAs(o,e.fileName+".pdf")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){o=r}else if(e.output=="dataurlnewwindow"){window.open(r)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=r}else if(e.output=="datastream"){location.href=r.replace("application/pdf","application/octet-stream")}if(t){t.apply(i,[o])}}else if(e.format=="image/png"||e.format=="png"){r=i.canvas.toDataURL("image/png");o=i.generateBlob(r,"image/png");if(e.output=="save"){saveAs(o,e.fileName+".png")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){o=r}else if(e.output=="dataurlnewwindow"){window.open(r)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=r}else if(e.output=="datastream"){location.href=r.replace("image/png","image/octet-stream")}if(t){t.apply(i,[o])}}else if(e.format=="image/jpeg"||e.format=="jpeg"||e.format=="jpg"){r=i.canvas.toDataURL("image/jpeg");o=i.generateBlob(r,"image/jpeg");if(e.output=="save"){saveAs(o,e.fileName+".jpg")}else if(e.output=="datastring"||e.output=="datauristring"||e.output=="dataurlstring"){o=r}else if(e.output=="dataurlnewwindow"){window.open(r)}else if(e.output=="datauri"||e.output=="dataurl"){location.href=r}else if(e.output=="datastream"){location.href=r.replace("image/jpeg","image/octet-stream")}if(t){t.apply(i,[o])}}}return i.generateOutput(e,r)},polifySVG:function(e){var t=this;function i(e,i){var r=e.getElementsByTagName(i);var o=r.length;while(o--){if(t.cfg.removeImagery){r[o].parentNode.removeChild(r[o])}else{var n=document.createElement("img");var a=document.createElement("canvas");var s=a.getContext("2d");a.width=r[o].getAttribute("width");a.height=r[o].getAttribute("height");n.src=r[o].getAttribute("xlink:href");n.width=r[o].getAttribute("width");n.height=r[o].getAttribute("height");try{s.drawImage(n,0,0,n.width,n.height);datastring=a.toDataURL()}catch(l){datastring=n.src;t.log("Tainted canvas, reached browser CORS security; origin from imagery must be equal to the server!");throw new Error(l)}r[o].setAttribute("xlink:href",datastring)}}}if(AmCharts.IEversion==0){e.setAttribute("xmlns","http://www.w3.org/2000/svg");if(!t.cfg.removeImagery){e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink")}}i(e,"pattern");i(e,"image");t.svgs.push(e);return e},generateSVG:function(){var e=this;var t=document.createElement("svg");t.setAttribute("xmlns","http://www.w3.org/2000/svg");t.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");for(var i=0;i<e.processing.buffer.length;i++){var r=document.createElement("g"),o=e.processing.buffer[i];o[0].setAttribute("xmlns","http://www.w3.org/2000/svg");o[0].setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");r.setAttribute("transform","translate("+o[1].x+","+o[1].y+")");r.appendChild(o[0]);t.appendChild(r)}return(new XMLSerializer).serializeToString(t)},generateOutput:function(e,t){var i=this,r=[],o=[],n=document.createElement("canvas"),a=n.getContext("2d"),s={y:0,x:0},r=i.chart.div.getElementsByTagName("svg");for(var l=0;l<r.length;l++)o.push(r[l]);if(i.chart.legend&&i.chart.legend.position=="outside"){i.chart.legend.container.container.externalLegend=true;o.push(i.chart.legend.container.container);if(i.cfg.legendPosition=="left"){s.x=i.chart.legend.div.offsetWidth}else if(i.cfg.legendPosition=="top"){s.y=i.chart.legend.div.offsetHeight}else if(typeof i.cfg.legendPosition=="object"){s.y=i.cfg.legendPosition.chartTop;s.x=i.cfg.legendPosition.chartLeft}}i.processing.buffer=[];i.processing.drawn=0;i.canvas=n;i.svgs=[];var u={x:0,y:0};for(var l=0;l<o.length;l++){var g=o[l].parentNode,d=Number(g.style.left.slice(0,-2)),f=Number(g.style.top.slice(0,-2)),c=i.polifySVG(o[l].cloneNode(true)),p=AmCharts.extend({},s);if(o[l].externalLegend){if(i.cfg.legendPosition=="right"){s.y=0;s.x=i.chart.divRealWidth}else if(i.cfg.legendPosition=="bottom"){s.y=f?f:s.y}else if(typeof i.cfg.legendPosition=="object"){s.x=i.cfg.legendPosition.left;s.y=i.cfg.legendPosition.top}else{s.x=0;s.y=0}}else{if(g.style.position=="relative"){s.x=d?d:s.x;s.y=f?f:s.y}else{s.x=d+u.x;s.y=f+u.y}}i.processing.buffer.push([c,AmCharts.extend({},s)]);if(f&&d){s=p}else{s.y+=f?0:g.offsetHeight}if(g.style.position=="absolute"&&g.getAttribute("class")=="amChartsLegend"){u.y+=g.parentNode.offsetHeight}}n.id=AmCharts.getUniqueId();n.width=i.chart.divRealWidth;n.height=i.chart.divRealHeight;if(i.chart.legend&&i.chart.legend.position=="outside"){if(["left","right"].indexOf(i.cfg.legendPosition)!=-1){n.width+=i.chart.legend.div.offsetWidth}else if(typeof i.cfg.legendPosition=="object"){n.width+=i.cfg.legendPosition.width;n.height+=i.cfg.legendPosition.height}else{n.height+=i.chart.legend.div.offsetHeight}}var m={width:false,height:false};if(i.chart.periodSelector){if(["left","right"].indexOf(i.chart.periodSelector.position)!=-1){n.width-=i.chart.periodSelector.div.offsetWidth+16;m.width=true}else{n.height-=i.chart.periodSelector.div.offsetHeight;m.height=true}}if(i.chart.dataSetSelector){if(["left","right"].indexOf(i.chart.dataSetSelector.position)!=-1){if(!m.width){n.width-=i.chart.dataSetSelector.div.offsetWidth+16}}else{n.height-=i.chart.dataSetSelector.div.offsetHeight}}if(e.backgroundColor||e.format=="image/jpeg"){a.fillStyle=e.backgroundColor||"#FFFFFF";a.fillRect(0,0,n.width,n.height)}function h(){var r,o,s,l;if(i.processing.buffer.length==i.processing.drawn||e.format=="svg"){return t()}else{o=i.processing.buffer[i.processing.drawn];l=(new XMLSerializer).serializeToString(o[0]);s=o[1];if(e.render=="browser"){r=new Image;r.id=AmCharts.getUniqueId();l="data:image/svg+xml;base64,"+btoa(l);r.onload=function(){a.drawImage(this,o[1].x,o[1].y);i.processing.drawn++;h()};r.onerror=function(){a.drawImage(this,o[1].x,o[1].y);i.processing.drawn++;h()};r.src=l;if(r.complete||typeof r.complete=="undefined"||r.complete===undefined){r.src="";r.src=l}}else if(e.render=="canvg"){canvg(n,l,{offsetX:s.x,offsetY:s.y,ignoreMouse:true,ignoreAnimation:true,ignoreDimensions:true,ignoreClear:true,renderCallback:function(){i.processing.drawn++;h()}})}}}return h()},generateButtons:function(){var e=this,t=0;var i;if(e.div){i=e.div;i.innerHTML=""}else{i=document.createElement("div"),e.div=i}function r(i){var o=document.createElement("ul");o.setAttribute("style","list-style: none; margin: 0; padding: 0;");for(var n=0;n<i.length;n++){var a=document.createElement("li"),s=document.createElement("img"),l=document.createElement("a"),u=i[n],g=null,d=AmCharts.extend(AmCharts.extend({},e.cfg.menuItemStyle),i[n]);u=AmCharts.extend(AmCharts.extend({},e.cfg.menuItemOutput),u);if(u["icon"]){s.alt="";s.src=u["icon"];s.setAttribute("style","margin: 0 auto;border: none;outline: none");if(u["iconTitle"]){s.title=u["iconTitle"]}l.appendChild(s)}l.href="#";if(u["title"]){s.setAttribute("style","margin: 0px 5px;");l.innerHTML+=u.title}l.setAttribute("style","display: block;");AmCharts.extend(l.style,d);l.onclick=u.onclick.bind(l,e,u);a.appendChild(l);if(u.items){g=r(u.items);a.appendChild(g);a.onmouseover=function(){g.style.display="block"};a.onmouseout=function(){g.style.display="none"};g.style.display="none"}o.appendChild(a);l.onmouseover=function(){this.style.backgroundColor=d.rollOverBackgroundColor;this.style.color=d.rollOverColor;this.style.borderColor=d.rollOverBorderColor};l.onmouseout=function(){this.style.backgroundColor=d.backgroundColor;this.style.color=d.color;this.style.borderColor=d.borderColor}}t++;return o}i.setAttribute("style","position: absolute;top:"+e.cfg.menuTop+";right:"+e.cfg.menuRight+";bottom:"+e.cfg.menuBottom+";left:"+e.cfg.menuLeft+";");i.setAttribute("class","amExportButton");i.appendChild(r(e.cfg.menuItems));e.chart.containerDiv.appendChild(i)}});
//# sourceMappingURL=amexport.map.js